package ripple.test.tools;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class UniqueRandomNumber {
    public static List<Integer> getRandomNumbers(int number, int start, int end) {
        if (end - start < number) {
            return null;
        }
        int[] numbers = new int[end - start];
        for (int i = 0; i < end - start; i++) {
            numbers[i] = start + i;
        }
        Random random = new Random();
        List<Integer> uniqueRandomNumbers = new ArrayList<>();
        for (int i = 0; i < number; i++) {
            int index = random.nextInt(end - start - i) + i;
            uniqueRandomNumbers.add(numbers[index]);
            numbers[index] = numbers[i];
        }

        System.out.println("UniqueRandomNumber");
        for (int i = 0; i < number; i++) {
            System.out.println(uniqueRandomNumbers.get(i) + " ");
        }
        System.out.println();

        return uniqueRandomNumbers;
    }
}
